import {imageUrl} from "../../utils/imageutil"
let app = getApp()
Page({


  data: {
    imageUrl,
    shareCode:'',
    ship_id:1,
    userInfo:wx.getStorageSync('userInfo')
  },

  onLoad(options) {
    if(options.ship_id){
      this.setData({
        ship_id:options.ship_id
      })
    }
    if(options.shareCode){
      this.setData({
        shareCode:options.shareCode
      })
    }
  },

  change_shareCode(e) {
    this.setData({
      shareCode: e.detail.value.replace(/s+/g, '') 
    })
  },
  to_url(){
    wx.navigateTo({
      url: '/pages/card_bag/index',
    })
  },
  // 使用分享卡券
  UseShareCode() {
    if(!this.data.shareCode){
      return
    }
    app.globalData.post({
      data: {
        do: 'UseShareCode',
        uid: wx.getStorageSync('userInfo').id,
        code: this.data.shareCode,
        ship_id: this.data.ship_id,
      }
    }).then(res => {
      if (res.data.code == 1) {
        // 兑换成功
        wx.showModal({
          content:'会员卡兑换成功',
          showCancel:false,
          confirmText:'知道了',
          confirmColor:'#FC7112'
        })
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
})